package org.ysu.controller;

import io.minio.errors.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.ysu.entity.Interview;
import org.ysu.service.InterviewService;
import org.ysu.vo.ResultVO;

import javax.annotation.Resource;
import java.io.IOException;
import java.math.BigDecimal;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 走访记录表 前端控制器
 * </p>
 *
 * @author LiuJunDa
 * @since 2024-08-16
 */
@RestController
@RequestMapping("/interview")
public class InterviewController {

    @Resource
    InterviewService interviewService;

    @PostMapping("/add")
    ResultVO<Boolean> add(Long vcId, Long fId, LocalDate time, String riskType, String riskRemark, BigDecimal income, BigDecimal liability, String suggestion, String detail, MultipartFile photo) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        return ResultVO.success(interviewService.add(vcId,fId,time,riskType,riskRemark,income,liability,suggestion,detail,photo),"添加走访记录成功");
    }

    @GetMapping("/list")
    public  ResultVO<List<Interview>> list(Long fId) {
        return  ResultVO.success(interviewService.list(fId));
    }

    @GetMapping("/getById")
    public ResultVO<Interview> getById(Long id) {
        return ResultVO.success(interviewService.getById(id));
    }

    @PostMapping("/update")
    public ResultVO<Boolean> update(Long id, Long fId, LocalDate time, String riskType, String riskRemark, BigDecimal income, BigDecimal liability, String suggestion, String detail, MultipartFile photo) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        return ResultVO.success(interviewService.update(id,fId,time,riskType,riskRemark,income,liability,suggestion,detail,photo),"更新走访信息成功");
    }

    @PostMapping("/del")
    public ResultVO<Boolean> del(Long id) {
        return ResultVO.success(interviewService.removeById(id),"删除走访信息成功");
    }

}
